package cn.etg.day06;

import java.io.*;

/**
 * 对myfile.txt文件进行复制操作，要求使用异常捕获
 * 机制对流的异常进行捕获和处理，finally中
 * 要将流关闭
 * @author Xiloer
 *
 */
public class Test01 {
    public static void main(String[] args) {
        File file =new File("myfile.txt") ;
        String file1 = "myfile_copy.txt";
        FileOutputStream fos = null;
        FileInputStream fis = null;
        try {
            file.createNewFile();
            fis = new FileInputStream(file);
            fos = new FileOutputStream(file1);
            byte[] bytes = new byte[1024*8];
            int d;
            while ((d = fis.read(bytes)) != -1) {
                fos.write(bytes, 0, d);
            }
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }finally {
            try {
                    fos.close();
                    fis.close();
            } catch (IOException e) {
                System.out.println(e.getMessage());
            }
        }
    }
}
